<template>
  <div class="region">
    <div class="content">
      <div class="left">地区:</div>
      <ul>
        <li :class="{active:isactive==-1}" @click="cliactive(-1,'')" class="{iscliactive}">全部</li>
        <li :class="{active:isactive==index}" v-for="(item,index) in reqdata" :key="item.id" @click="cliactive(index,item)">{{item.name}}</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang='ts'>
import { ref,onMounted,defineEmits } from 'vue'
// 获取数据展示
import {reqHospitalLevelAndRegion} from "@/api/home/index"
import type { HospitalLevelAndRegionResponseData, HospitalLevelAndRegionArr} from "@/api/home/types";
const reqdata=ref()
onMounted(()=>{
  getData()
})

const getData=async()=>{
  let result:HospitalLevelAndRegionResponseData=await reqHospitalLevelAndRegion("Beijin")
  //存储全部地区的数据
  if (result.code == 200) {
    reqdata.value = result.data;
  }
}

// 点击获取样式
const emits=defineEmits(["getRegion"])
let isactive=ref<number>(-1)
const cliactive=(index:number,item:any)=>{
  isactive.value=index;
  emits("getRegion",item.value)
}
</script>

<script lang="ts">
export default {
    name:"region"
}
</script>

<style scoped lang="scss">
.region {
  color: #7f7f7f;
  margin-top: 20px;
  .content {
    display: flex;
    .left {
      margin-right: 10px;
      width: 50px;
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      li {
        margin-right: 10px;
        margin-bottom: 10px;
        &.active {
          color: #55a6fe;
        }
      }
      li:hover {
        color: #55a6fe;
      }
    }
  }
}
</style>
